<!DOCTYPE HTML>
<html th:with="title='编辑优惠券',module='/js/app/common/uploadvideo.js'">
<head th:include="fragments/UEheader :: header">
<style type="text/css">
</style>
</head>
<body id="app">
	<div class="page-container">
		<form class="form form-horizontal" id="form">
			<input type="hidden" name="id" v-model="coupon.id" />
			<input type="hidden" name="adsType" v-model="coupon.adsType"/>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					商家名称：
				</label>
				<div class="formControls col-xs-2 col-sm-2">
					<input type="text" class="input-text radius size-L" v-model="coupon.adBusinessName" id="adBusinessName" name="adBusinessName">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					优惠券名称：
				</label>
				<div class="formControls col-xs-2 col-sm-2">
					<input type="text" class="input-text radius size-L" v-model="coupon.adName" id="adName" name="adName">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					有效时间：
				</label>
				<div class="formControls col-xs-4 col-sm-4">
					<input type="text" placeholder="开始时间" class="input-text size-S laydate-icon" th:value="${lastDay}" style="width: 150px;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss', start: laydate.now(-1),  min: laydate.now(-180), max: laydate.now(30)})" v-model="coupon.adStartTime" id="daybegin" name="adStartTime">
					-
					<input type="text" placeholder="结束时间" class="input-text size-S laydate-icon" th:value="${lastDay}" style="width: 150px;" onclick="laydate({istime: true, format: 'YYYY-MM-DD hh:mm:ss', start: laydate.now(-1),  min: laydate.now(-180), max: laydate.now(30)})" v-model="coupon.adEndTime" id="dayend" name="adEndTime">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					联系方式：
				</label>
				<div class="formControls col-xs-2 col-sm-2">
					<input type="text" class="input-text radius size-L"  v-model="coupon.adMobilePhone" id="adMobilePhone" name="adMobilePhone">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">商家地址：</label>
				<div class="formControls col-xs-2 col-sm-2">
					<input type="text" class="input-text radius size-L"  v-model="coupon.adBusinessAddr" id="adBusinessAddr" name="adBusinessAddr">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">优惠券说明：</label>
				<div class="formControls col-xs-2 col-sm-2">
					<input type="text" class="input-text radius size-L"  v-model="coupon.adRemark" id="adRemark" name="adRemark">
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					优惠券图片：
				</label>
				<input type="hidden" id="backgroundImg" name="adImage">
				<div class="col-xs-2 col-sm-2 col-xs-offset-4 col-sm-offset-4" style="margin: 0;">
					<div id="uploader-demo">
						<!--用来存放item-->
						<div id="fileList" class="uploader-list"></div>
						<div id="filePicker" class="btn btn-primary size-L radius ">选择图片</div>
					</div>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					优惠券二维码：
				</label>
				<input type="hidden" id="adQrcode" name="adQrcode">
				<div class="col-xs-2 col-sm-2 col-xs-offset-4 col-sm-offset-4" style="margin: 0;">
					<div id="uploader-demo">
						<!--用来存放item-->
						<div id="QrCodefileList" class="uploader-list"></div>
						<div id="QrCodefilePicker" class="btn btn-primary size-L radius ">选择图片</div>
					</div>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					选择模板：
				</label>
				<div class="formControls col-xs-2 col-sm-2">
					<select class="input-text size-L"  v-model="coupon.appTemplate.id" id="appTemplate" name="appTemplate">
					</select>
				</div>
			</div>
			<div class="row cl">
				<label class="form-label col-xs-4 col-sm-3">
					<span class="c-red">*</span>
					优惠券海报：
				</label>
				<input type="hidden" id="adIntroduction" name="adIntroduction">
				<div class="col-xs-2 col-sm-2 col-xs-offset-4 col-sm-offset-4" style="margin: 0;">
					<div id="uploader-demo">
						<!--用来存放item-->
						<div id="adIntfileList" class="uploader-list"></div>
						<div id="adIntfilePicker" class="btn btn-primary size-L radius ">选择图片</div>
					</div>
				</div>
			</div>
			<div class="row cl">
				<div class="text-c">
					<input class="btn btn-primary size-L radius mr-10" type="submit" value="提交">
					<input class="btn btn-danger size-L radius" type="button" onclick="closeWin()" value="关闭">
				</div>
			</div>
		</form>
	</div>

	<script type="text/javascript">
	var ue = UE.getEditor('container');
	var app = new Vue({
		el : '#app',
		data : {
			coupon : []
		}
	});
		function closeWin() {
			var index = parent.layer.getFrameIndex(window.name);
			parent.layer.close(index);
		}
		//获取当前营销详情
		function get() {
			var id = getIdFromUrl();
			$.ajax({
				type : "POST",
				url : '/manager/ads/get/' + id,
				beforeSend : function() {
				},
				complete : function() {
				},
				error : function(request) {
					alert("Connection error");
				},
				success : function(result) {
					if (result.status == 0) {
						var data = result.data;
						//优惠券图处理
						if (data.adImage != "") {
							$("#fileList").append("<img src='"+data.adImage+"'  width='100' height='100'>");
							$("#backgroundImg").val(data.adImage);
						}
						//二维码处理
						if (data.adQrcode != "") {
							$("#QrCodefileList").append("<img src='"+data.adQrcode+"'  width='100' height='100'>");
							$("#adQrcode").val(data.adQrcode);
						}
						//优惠券海报处理
						if (data.adIntroduction != "") {
							$("#adIntfileList").append("<img src='"+data.adIntroduction+"'  width='100' height='100'>");
							$("#adIntroduction").val(data.adIntroduction);
						}
						//商品描述
						if (data.adIntroduction != null) {
							ue.ready(function() {
								ue.setContent(data.adIntroduction);
							});
						}
						app.coupon = data;
					}
				}
			});
		}
		/*
		 * 查询
		 */
		function adsQuery() {
			var tip = layer.load(0, {
				shade : false
			});
			$.ajax({
				type : "POST",
				url : '/manager/appTemplate/findAll',
				data : {
					search_IN_templateType_templateTypeSn : "004,009"
				},
				beforeSend : function() {
				},
				complete : function() {
					layer.close(tip);
				},
				error : function(request) {
					layer.alert("系统错误");
				},
				success : function(result) {
					if (result.status == 0) {
						var data = result.data;
 						for ( var i = 0; i < data.length; i++) {
							$("#appTemplate").append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
						}
 						get();
					} else {
						sessionCheckTimeOut(result);
					}
				}
			});
		}
		$(function() {
			adsQuery();
			var ue = UE.getEditor('container');
			$("#form").validate({
				rules : {
					adBusinessName : {
						required : true
					},
					adName : {
						required : true
					},
					adStartTime : {
						required : true
					},
					adEndTime : {
						required : true
					},
					adMobilePhone : {
						required : true
					},
					adImage : {
						required : true
					},
					adQrcode : {
						required : true
					}
				},
				onkeyup : false,
				focusCleanup : true,
				success : "valid",
				submitHandler : function(form) {
					var data = $('#form').serialize();
					$.ajax({
						type : "POST",
						url : '/manager/ads/update',
						data : data,
						beforeSend : function() {

						},
						complete : function() {
							
						},
						error : function(request) {
							layer.alert("系统出错！");
						},
						success : function(data) {
							if (data.status == 0) {
								refreshUParentList();
								layer.alert(data.message, function() {
									var index = parent.layer.getFrameIndex(window.name);
									parent.layer.close(index);
								});
							} else {
								layer.alert(data.message);
							}
						}
					});
				}
			});
		});
	</script>
</body>
</html>